# _*_ coding: utf-8 _*_
# @Time : 2024-01-25 17:04
# @Author : WF

"""
pyautogu上篇文章已经详细说明了，但是由于输入格式问题，只能输入英文，
所以pyperclip 将文本内容复制到粘贴板，然后用pyautogu进行键盘粘贴操作

pip install pyperclip


NotImplementedError: The confidence keyword argument is only available if OpenCV is installed.
pip install opencv_python
"""

import pyautogui
import pyperclip

# 每次延迟 1s
pyautogui.PAUSE = 2

pyautogui.FAILSAFE = True

wechat_id = "测试自动发"

# 返回主界面
pyautogui.hotkey('win', 'm')

# 获取 微信位置，并双击
# location = pyautogui.locateOnScreen('微信.png', confidence=0.7)
location = pyautogui.locateOnScreen('step1.png', confidence=0.7)
print(location)
pyautogui.doubleClick(location)

# 搜索图标
# location = pyautogui.locateOnScreen('微信搜索.png', confidence=0.7)
location = pyautogui.locateOnScreen('step2.png', confidence=0.7)
print(location)
pyautogui.doubleClick(location)
pyperclip.copy(wechat_id)
pyautogui.hotkey('ctrl', 'v')
pyautogui.typewrite(wechat_id)

pyautogui.moveTo(1000, 1120)
# 单击鼠标
pyautogui.click()

with open('发送语录.txt', 'r', encoding='utf-8') as fp:
    line_lists = fp.readlines()

for line in line_lists:
    line = line.strip('\n')
    if not line:
        continue
    print(line)
    pyperclip.copy(line)

    # 粘贴，发送
    pyautogui.hotkey('ctrl', 'v')
    pyautogui.press('enter')


